/**
 * 按钮基类
 * @param bitmapData
 * @param width
 * @param height
 */
SimpleButton = function( bitmapData,width,height )
{
	Bitmap.call(this,bitmapData);
	this.className="SimpleButton";
	this.setWidth(width) ;
	this.setHeight(height) ;
	this.mouseEnabled = true ; //默认是有鼠标事件的
	this.useHandCursor = false ; //鼠标在上面时是否显示成手形

	this._enabled = true ;
	this._upRect ;
	this._overRect ;
	this._downRect ;
	this._disabledRect ;
};
FLASH.extend(SimpleButton,Bitmap); //继承自Bitmap

//===============getter/setter===========================

SimpleButton.prototype.setEnabled = function( value ){
	this._enabled = value ;
	this.mouseEnabled = value ;
};
SimpleButton.prototype.getEnabled = function(){ return this._enabled ; };

//===================================================

SimpleButton.prototype.setUpRect = function ( rect )
{
	this._upRect = rect ;
	this._currentRect = rect ;
	return this ;
};
SimpleButton.prototype.setOverRect = function ( rect )
{
	this._overRect = rect ;
	return this ;
};
SimpleButton.prototype.setDownRect = function ( rect )
{
	this._downRect = rect ;
	return this ;
};
SimpleButton.prototype.setDisabledRect = function ( rect )
{
	this._disabledRect = rect ;
	return this ;
};
/**
 * 释放资源
 */
SimpleButton.prototype.dispose = function()
{
	Bitmap.prototype.dispose.call(this);
	this._upRect = null ;
	this._overRect = null ;
	this._downRect = null ;
	this._disabledRect = null ;
};

//=========私有方法=========================
/**
 * 输出
 * @param globalAlpha 
 * @param context
 */
SimpleButton.prototype._draw =function( globalAlpha,context )
{
	if( !this._enabled && this._disabledRect ){
		this._currentRect = this._disabledRect ;
	}
	Bitmap.prototype._draw.call(this , globalAlpha , context) ;
};

//===========鼠标事件处理============================
/**
 * 鼠标在上面
 */
SimpleButton.prototype._onMouseOver= function( ctrlKey, altKey,shiftKey, buttonDown, delta )
{
	if (this._enabled && InteractiveObject.prototype._onMouseOver.call(this , ctrlKey, altKey,shiftKey, buttonDown, delta )
			&&this._overRect )
	{
		if( Mouse._isShow && this.useHandCursor) {
			FlashCore.canvas.style.cursor = "pointer";
		}
		this._currentRect = this._overRect ;
	}
};
/**
 * 鼠标移出此对象
 */
SimpleButton.prototype._onMouseOut = function( ctrlKey, altKey,shiftKey, buttonDown, delta )
{
	if (this._enabled && InteractiveObject.prototype._onMouseOut.call(this , ctrlKey, altKey,shiftKey, buttonDown, delta )
			&&this._upRect )
	{
		this._currentRect = this._upRect ;
		this._setMouseDefault();
	}
};
/**
 * 鼠标按下
 */
SimpleButton.prototype._onMouseDown = function( ctrlKey, altKey,shiftKey, buttonDown, delta )
{
	if (this._enabled && InteractiveObject.prototype._onMouseDown.call(this , ctrlKey, altKey,shiftKey, buttonDown, delta )
			&&this._downRect )
	{
		this._currentRect = this._downRect ;
		this._setMouseDefault();
	}
};
/**
 * 鼠标弹起
 */
SimpleButton.prototype._onMouseUp = function( ctrlKey, altKey,shiftKey, buttonDown, delta )
{
	if (this._enabled && InteractiveObject.prototype._onMouseUp.call(this , ctrlKey, altKey,shiftKey, buttonDown, delta )
			&&this._overRect )
	{
		this._currentRect = this._overRect ;
		this._setMouseDefault();
	}
};


//=============私有方法=====================
/**
 * 将鼠标设置成默认的
 */
SimpleButton.prototype._setMouseDefault = function()
{
	if( Mouse._isShow && this.useHandCursor && FlashCore.canvas.style.cursor!="default") {
		FlashCore.canvas.style.cursor = "default";
	}
};